<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>
</head>

<body>

  <div class="page-group">
    <div class="page page-current">

      <header class="bar bar-nav fs-header-small">
        <a onclick="window.history.back();" class="icon icon-left pull-left"></a>
        <h1 class="title">第${batchCourseware.sorting}周课件</h1>
      </header>
      
      <nav class="bar bar-tab" style="padding: 0 .5rem;">
        <c:choose>
          <c:when test="${batchCourseware.sorting >1}">
            <a class="tab-item external" href="${ctx.host}/rounds/${courseRound.id}/batch-coursewares?type=${batchCourseware.type}&week=${batchCourseware.sorting-1}">
              <span class="icon icon-left" style="font-size: .7rem;"></span>
              <span class="tab-label" style="font-size: .7rem;">上一周</span>
            </a>
          </c:when>
          <c:otherwise>
            <a class="tab-item external" href="javascript:void(0);">
            </a>
          </c:otherwise>
        </c:choose>
        <c:choose>
          <c:when test="${not batchCourseware.editStatus.generated}">
            <a class="tab-item external" href="javascript:void(0);" style="width: 4%; padding: 0 .5rem;">
              <button class="button button-light batch-link" style="width: 100%; position: static; height: 1.5rem; line-height: 1.5rem; background: #FEDC32; color: #555;">发送课件</button>
            </a>
          </c:when>
          <c:otherwise>
            <a class="tab-item external" href="javascript:void(0);" style="width: 4%; padding: 0 .5rem;">
            </a>
          </c:otherwise>
        </c:choose>
        <fmt:formatNumber var="index" type="number" value="${(courseRound.fitnessGroup.hours-courseRound.fitnessGroup.hours%12)/12}"/>
        <c:choose>
          <c:when test="${(batchCourseware.type.weekly and batchCourseware.sorting < courseRound.fitnessGroup.weeks) or (batchCourseware.type.course and batchCourseware.sorting < index)}">
            <a class="tab-item external" href="${ctx.host}/rounds/${courseRound.id}/batch-coursewares?type=${batchCourseware.type}&week=${batchCourseware.sorting+1}">
              <span class="icon icon-right" style="font-size: .7rem;"></span>
              <span class="tab-label" style="font-size: .7rem;">下一周</span>
            </a>
          </c:when>
          <c:otherwise>
            <a class="tab-item external" href="javascript:void(0);">
            </a>
          </c:otherwise>
        </c:choose>
        
      </nav>

      <div class="content">
        <div class="buttons-tab">
          <a href="${ctx.host}/rounds/${courseRound.id}/batch-coursewares?type=${batchCourseware.type}&week=${batchCourseware.sorting}" class="active button">动作</a>
          <a href="${ctx.host}/rounds/${courseRound.id}/batch-coursewares/${batchCourseware.id}/diet" class="button">饮食</a>
        </div>
        
        <div class="exercise-wrap">
          <c:forEach var="daily" items="${batchCourseware.dailyCoursewares}">
            <c:set var="coursewares" value="${persist.courseware(daily.id)}"/>
            <div class="card" style="margin: .5rem 0;">
              <div class="card-header">${daily.name}
                <c:choose>
                  <c:when test="${not (daily.type.rest and empty coursewares)}">
                    <a class="daily-rest add-action" data-daily="${daily.id}" data-rest="${daily.type.rest and empty coursewares ? '1' : '0'}">设为休息</a>
                  </c:when>
                  <c:otherwise>
                    <a href="javascript:void(0);" data-daily="${daily.id}" class="set-action reset-action-${daily.id}">重新添加动作</a>
                    <a class="daily-rest add-action set-rest-${daily.id}" data-daily="${daily.id}" data-rest="${daily.type.rest and empty coursewares ? '1' : '0'}" style="display:none;">设为休息</a>
                  </c:otherwise>
                </c:choose>
              </div>
              <c:choose>
                <c:when test="${empty daily.type or (not daily.type.rest and empty coursewares)}">
                  <div class="card-content">
                    <c:forEach var="type" items="${enums['coursewareMovementType']}">
                      <div class="card-content-inner">
                        <div class="action-header">
                          <label class="action-title">${type.description}</label>
                        </div>
                        <ul class="action-content">
                          <li class="action-item">
                            <a href="#movement-btn" data-daily="${daily.id}" data-type="${type.alias}" data-toggle="push" class="add-action"><i class="icon-add"></i></a>
                          </li>
                        </ul> 
                      </div>
                    </c:forEach>
                  </div>
                </c:when>
                <c:when test="${daily.type.rest and empty coursewares}">
                  <div class="card-content daily-card-${daily.id}" style="display: block;">
                    <div class="card-content-inner">
                      <ul class="action-content">
                        <li style="list-style: none;"><p style="font-size: .7rem; color: #999; text-align: center;">今日休息</p></li>
                      </ul>
                    </div>
                  </div>
                  <div class="card-content action-card-${daily.id}" style="display: none;">
                    <c:forEach var="type" items="${enums['coursewareMovementType']}">
                      <div class="card-content-inner">
                        <div class="action-header">
                          <label class="action-title">${type.description}</label>
                        </div>
                       <ul class="action-content">
                         <li class="action-item">
                           <a href="#movement-btn" data-daily="${daily.id}" data-type="${type.alias}" data-toggle="push" class="add-action"><i class="icon-add"></i></a>
                         </li>
                       </ul>
                      </div>
                    </c:forEach>
                  </div>
                </c:when>
                <c:otherwise>
                  <c:forEach var="type" items="${enums['coursewareMovementType']}">
                    <div class="card-content-inner">
                      <div class="action-header">
                        <label class="action-title">${type.description}</label>
                      </div>
                      <ul class="action-content">
                        <c:forEach var="courseware" items="${coursewares[type.alias]}">
                          <li class="action-item">
                            <a href="javascript:void(0);" class="movement-edit" data-daily="${daily.id}" 
                                                                                data-courseware="${courseware.id}" 
                                                                                data-amount="${courseware.groupAmount}" 
                                                                                data-number="${courseware.movementNumber}" 
                                                                                data-weight="${courseware.maxWeight}" 
                                                                                data-time="${courseware.time}">
                              <div class="action-cover">
                                <img src="${cloud.prod}/${courseware.movement.cover}-0.6" alt="" />
                                <span>${courseware.movement.name}</span>
                              </div>
                              <p class="no-margin text-center">
                                <c:if test="${courseware.groupAmount != 0}">${courseware.groupAmount}组&nbsp;</c:if>
                                <c:if test="${courseware.movementNumber != 0}">${courseware.movementNumber}次&nbsp;</c:if>
                                <c:if test="${not empty courseware.maxWeight}">Max&nbsp;${courseware.maxWeight}KG&nbsp;</c:if>
                                <c:if test="${not empty courseware.time}">${courseware.time}s</c:if>
                              </p>
                            </a>
                            <a class="close-module" data-courseware="${courseware.id}" data-daily="${daily.id}"></a>
                          </li>
                        </c:forEach>
                        <li class="action-item">
                          <a href="#movement-btn" data-daily="${daily.id}" data-type="${type.alias}" data-toggle="push" class="add-action"><i class="icon-add"></i></a>
                        </li>
                      </ul>
                    </div>
                  </c:forEach>
                </c:otherwise>
              </c:choose>
            </div>
        </c:forEach>
      </div>
          
    </div>
  </div>  
</div>

  <%@ include file="/WEB-INF/include/script.jsp"%>
  <d:resource root="${ctx.resource}/build" type="script" src="js/page/courseware/batch-courseware-list.js" />
  <script type="text/javascript">
    require(['page/courseware/batch-courseware-list'], function(page) {
      page.init({
          'roundId': '${courseRound.id}',
          'batchId': '${batchCourseware.id}',
          'type': '${batchCourseware.type}',
          'categories': JSON.parse('${persist.movementCategories}'),
          'equipments': JSON.parse('${persist.movementEquipments}'),
          'groups': JSON.parse('${persist.fitnessGroups}')
      })
    })
  </script>

</body>
</html>